function myChart(data, element, chartType) {
var ctx = document.getElementById(element).getContext('2d');
var myChart = new Chart(ctx, {
    type: 'bar',
    data: data,
    options: {
        scales: {
            y: {
                beginAtZero: true
            }
        }
    }
});






}
function Q(time){
	if (time===""){
	var data={}
	data.start_date=$("#start_date").val()
	data.end_date=$("#end_date").val()
	data=JSON.stringify(data)
	}
	else{
		var data=""}
	$("#tab>tr").remove()
	$.ajax({
		"url":"/admin_query/",
		"error":errorAjax,
		"beforeSend":start_load_pic,
		"complete":stop_load_pic,
		"data":{"time":time,"date":data},
		"dataType":"jsonp",
		"success":function(data){
			if(responseCheck(data)){
				var T={
					"labels":[],
					"datasets":[{
						"label":"",
						"backgroundColor":"#62a8ea",
						"data":[],
						
					}]
				}
				for (var key in data.statistics){
					T.labels.push(key)
					T.datasets[0].data.push(data.statistics[key])
				}
				if(time==="today"){
					$("#title1").text("今日各加油站销售统计图(元)")
					$("#title2").text("今日各种燃油销售统计图(元)")
				}
				else if(time==="week"){
					$("#title1").text("近七天各加油站销售统计图(元)")
					$("#title2").text("近七天各种燃油销售统计图(元)")
				}
				else if(time==="mon"){
					$("#title1").text("本月各加油站销售统计图(元)")
					$("#title2").text("本月各种燃油销售统计图(元)")
				}
				else{
					$("#title1").text($("#start_date").val() +"至" +$("#end_date").val()+ "各加油站销售统计图(元)")
					$("#title2").text($("#start_date").val() +"至" +$("#end_date").val()+ "各种燃油销售统计图(元)")
				}
			
				$("#d1>canvas").remove()
				var canvas=document.createElement("canvas")
				canvas.setAttribute("id","bar1")
				document.getElementById("d1").appendChild(canvas)

				$("#d2>canvas").remove()
				var canvas=document.createElement("canvas")
				canvas.setAttribute("id","bar2")
				document.getElementById("d2").appendChild(canvas)
				if(T.labels.length==0){
					showErrorInfo("当前无数据！")
					return false;
				}

				myChart(T,"bar1","Bar")

				//第二个燃油单位图
				var T={
					"labels":[],
					"datasets":[{
						"label":"",
						"backgroundColor":"green",
						"data":[],
						
					}]
				}
				for (var key in data.statistics2){
					T.labels.push(key)
					T.datasets[0].data.push(data.statistics2[key])
				}
				
				myChart(T,"bar2","Bar")
					

			}
		}
	})
}
document.getElementById("day").onclick=function(){
	$("#start_date").val("")
	$("#end_date").val("")
	Q("today")
}
document.getElementById("week").onclick=function(){
	$("#start_date").val("")
	$("#end_date").val("")
	Q("week")
}
document.getElementById("mon").onclick=function(){
	$("#start_date").val("")
	$("#end_date").val("")
	Q("mon")
}
document.getElementById("mon").onclick=function(){
	$("#start_date").val("")
	$("#end_date").val("")
	Q("mon")
}
document.getElementById("qq").onclick=function(){
	Q("")
}
document.getElementById("reset").onclick=function(){
	$("#start_date").val("")
	$("#end_date").val("")
}
Q("today")
